package com.my.mymafengwo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.smallstrong.mafengwopro.R;
import com.my.mymafengwo.bean.SearchData;

import java.util.List;

/**
 * ***********************************************
 * author:ljz
 * time:2015/12/4 14:44
 * name:搜索热门旅游景点页面所使用的适配器
 * step:
 * ***********************************************
 */
    public  class SearchGridAdapter extends BaseAdapter {
    private Context context;
    private List<SearchData.DataEntity.ListEntity.ListEntity2> data;
    public SearchGridAdapter(Context context){
        this.context=context;
    }


    public void setData(List<SearchData.DataEntity.ListEntity.ListEntity2> data) {
        this.data = data;
    }
    @Override
        public int getCount() {
        return data == null ? 0 : data.size();
        }

        @Override
        public Object getItem(int position) {
            return data.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            final ViewHolder holder;
            if(convertView == null) {
                convertView = View.inflate(context, R.layout.item_search, null);
                holder = new ViewHolder();
                holder.tv = (TextView) convertView.findViewById(R.id.tv_hot);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.tv.setText(data.get(position).getName());
            return convertView;
        }
        class ViewHolder {
            TextView tv;
        }
    }